package cn.buddha.jec.exception;

import cn.buddha.jec.exception.enums.TongExceptionEnum;
import cn.buddha.jec.exception.model.TongExceptionResult;
import cn.buddha.jec.model.TongBaseResponse;
import cn.buddha.jec.model.head.TongOutHead;

/**
 * @ClassName TongBusinessResult
 * @Author 友野浩二
 * @Description 公共响应处理
 * @Version 1.0
 */
public class TongBusinessResult {

    /**
     * @return com.tong.hao.common.entity.api.TongBaseResponse
     * @Author 友野浩二
     * @Description // 当发生业务异常时,全局异常处理类会进行捕获,在捕获到异常后,调用该方法进行错误信息封装。
     * @Param [retCode, retMsg]
     **/
    public static TongBaseResponse error(String retCode, String retMsg) {
        TongExceptionResult exceptionResult = TongExceptionResult.exception(retCode, retMsg);
        TongOutHead tongOutHead = new TongOutHead(exceptionResult);
        TongBaseResponse tongBaseResponse = new TongBaseResponse();
        tongBaseResponse.setTongOutHead(tongOutHead);
        return tongBaseResponse;
    }

    /**
     * @return com.tong.hao.common.entity.api.head.TongOutHead
     * @Author 友野浩二
     * @Description // API接口执行成功后的响应头封装
     * @Param [retCode, retMsg]
     **/
    public static TongOutHead success() {
        TongExceptionResult exceptionResult = TongExceptionResult.exception(TongExceptionEnum.SUCCESS.getCode(),
                TongExceptionEnum.SUCCESS.getMessage());
        return new TongOutHead(exceptionResult);
    }

}
